package cn.com.dashihui.web.service;

import java.util.List;

import cn.com.dashihui.web.dao.Category;
import cn.com.dashihui.web.dao.City;
import cn.com.dashihui.web.dao.GoodsTag;
import cn.com.dashihui.web.dao.Logistics;
import cn.com.dashihui.web.dao.Seller;
import cn.com.dashihui.web.dao.Store;

public class APIService {
	
	public List<City> getAllProvince(){
		return City.me().find("SELECT id,name FROM t_dict_city WHERE type=1");
	}
	
	public List<City> getAllCityByProvince(int provinceid){
		return City.me().find("SELECT id,name FROM t_dict_city WHERE type=2 AND parentid=?",provinceid);
	}
	
	public List<City> getAllAreaByCity(int cityid){
		return City.me().find("SELECT id,name FROM t_dict_city WHERE type=3 AND parentid=?",cityid);
	}
	
	public List<Category> getCategoryByParent(int parentid){
		return Category.me().find("SELECT categoryId id,categoryName name FROM t_dict_category WHERE categoryFatherId=? ORDER BY categoryNo",parentid);
	}
	
	public List<Store> getStoreAll(){
		return Store.me().find("SELECT A.id,A.title FROM t_dict_store A ORDER BY A.createDate DESC");
	}
	
	public List<Logistics> getLogistics(){
		return Logistics.me().find("SELECT A.* FROM t_dict_logistics A WHERE A.state=1");
	}

	public List<Seller> getSellerAll() {
		return Seller.me().find("SELECT A.sellerId,A.sellerName FROM t_bus_seller A where A.state=2 ORDER BY A.createtime DESC");
	}
	public List<Seller> getSellerAllState() {
		return Seller.me().find("SELECT A.sellerId,A.sellerName FROM t_bus_seller A where A.state=2 ORDER BY A.createtime DESC");
	}
	public List<Store> getStoreState(String parentidStr) {
		return Store.me().find("SELECT A.storeid,A.title FROM t_dict_store A where A.state=2 and A.qstate !=3 and A.sellerId=?",parentidStr);
	}
	public List<Store> getStore(String parentidStr) {
		return Store.me().find("SELECT A.storeid,A.title FROM t_dict_store A where A.state=2 and A.sellerId=?",parentidStr);
	}
	public List<Store> getStores(String parentidStr,int goodsid) {
		return Store.me().find("SELECT A.storeid,A.title FROM t_dict_store A left join t_bus_goods_store_rel B on A.storeid=B.storeid "
				+ " left join t_bus_goods C on B.goodstore=C.good_store where A.sellerId=? and C.id=?",parentidStr,goodsid);
	}

	public List<GoodsTag> getTag() {
		return GoodsTag.me().find("select id,tagName from t_bus_goods_tag order by orderNo");
	}
}
